package com.fxd.cloudconsumerorder80.controller;

import com.fxd.cloudapicommons.entities.CommonResult;
import com.fxd.cloudapicommons.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author xudongfu
 * @date 2025/03/30
 */
@RestController
@Slf4j
@RequestMapping("/consumer/payment")
public class OrderController {

    private static final String PAY_URL = "http://localhost:8001";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/create")
    public CommonResult<Payment> create(Payment payment) {
        return restTemplate.postForObject(PAY_URL + "/payment/create",
                payment,
                CommonResult.class
        );
    }

    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAY_URL + "/payment/get/" + id,
                CommonResult.class
        );
    }
}
